package userRecycleModuleApi

import (
	"KumquatDrivesServices/common/res"
	"KumquatDrivesServices/enums"
	"KumquatDrivesServices/global"
	"KumquatDrivesServices/model"
	"KumquatDrivesServices/utils"
	"errors"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"gorm.io/gorm"
	"time"
)

func (UserRecycleModuleApi) GetRecycleFolderContents(c *gin.Context) {
	userId := utils.GetUserId(c)
	var fileModel []model.FileModel
	now := time.Now()
	tenDaysAgo := now.AddDate(0, 0, -10).Unix()
	query := global.DB.Where("user_id=? and del_flag=? AND recovery_time >= ?", userId, enums.RecycleBin, tenDaysAgo).
		Order("is_folder desc, recovery_time desc")
	if err := query.Find(&fileModel).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		logrus.Errorf("GetRecycleFolderContents err:%v", err)
		res.FailWithCode(res.SYS_ERR, c)
		return
	}
	res.OkWithData(fileModel, c)
}
